package cn.cq.admin.controller;

import cn.cq.annotation.OperationLogAnnotation;
import cn.cq.admin.entity.dto.BatchRemove;
import cn.cq.admin.entity.dto.RoleDto;
import cn.cq.admin.entity.dto.RolePageDto;
import cn.cq.admin.service.TRoleService;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * cn.cq.admin.controller
 *
 * @author dicraft

 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private TRoleService roleService;

    /**
     * 新增角色
     * @param roleDto
     * @return
     */
    @OperationLogAnnotation(module = "角色管理",type = "新增",description = "新增角色")
    @SaCheckPermission(value = "Settings-Role-Add", orRole = "SUPER-ADMIN")
    @PostMapping("/doSave")
    public SaResult doSave(@RequestBody RoleDto roleDto){
        return roleService.doSave(roleDto);
    }

    /**
     * 修改角色
     * @param roleDto
     * @return
     */
    @OperationLogAnnotation(module = "角色管理",type = "修改",description = "修改角色")
    @SaCheckPermission(value = "Settings-Role-Modify", orRole = "SUPER-ADMIN")
    @PutMapping("/doModify")
    public SaResult doModify(@RequestBody RoleDto roleDto) {
        return roleService.doModify(roleDto);
    }

    /**
     * 删除角色（支持单条、批量）
     * @param batchRemove
     * @return
     */
    @OperationLogAnnotation(module = "角色管理",type = "删除",description = "删除角色（支持单条、批量）")
    @SaCheckPermission(value = "Settings-Role-Remove", orRole = "SUPER-ADMIN")
    @DeleteMapping("/doRemove")
    public SaResult doRemove(@RequestBody BatchRemove batchRemove) {
        return roleService.doRemove(batchRemove.getIds());
    }

    /**
     * 获取角色列表（分页）
     * @param pageDto
     * @return
     */
    @OperationLogAnnotation(module = "角色管理",type = "查询",description = "获取角色列表（分页）")
    @SaCheckPermission(value = "Settings-Role-Query", orRole = "SUPER-ADMIN")
    @PostMapping("/doList")
    public SaResult doList(@RequestBody RolePageDto pageDto){
        return roleService.doList(pageDto);
    }

    /**
     * 获取角色列表（非分页）
     * @return
     */
    @OperationLogAnnotation(module = "角色管理",type = "查询",description = "获取角色列表（非分页）")
    @SaCheckPermission(value = "Settings-Role-Query", orRole = "SUPER-ADMIN")
    @GetMapping("/doAll")
    public SaResult doAll(){
        return roleService.doAll();
    }
}
